package com.wql;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import com.wql.web.mapper.AdminMapper;
import com.wql.web.model.AdminSqlParam;
import com.wql.web.model.AdminWithBLOBs;

public class Test {

	public static void main(String[] args) {
		String resource = "mybatis-conf.xml";
		InputStream is = Test.class.getClassLoader().getResourceAsStream(resource);
		SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(is);
		SqlSession session = sessionFactory.openSession();
		AdminMapper mapper = session.getMapper(AdminMapper.class);
		List<AdminWithBLOBs> list = new ArrayList<AdminWithBLOBs>();
		for (int i = 0; i < 5; i++) {
			AdminWithBLOBs record = new AdminWithBLOBs();
			record.setAddtime(new Date());
			record.setEnable(i % 2 == 0);
			record.setName("name_" + i);
			list.add(record);
		}
		System.out.println("-----------测试批量插入-------------");
		System.out.println("updates: " + mapper.insertBatchBySelective(list, list.get(0)));
		session.commit();
		list = mapper.selectByParamWithBLOBs(new AdminSqlParam());
		System.out.println("-------------------------");
		for (AdminWithBLOBs record : list) {
			System.out.println(record);
		}
	}

}
